# encoding: UTF-8
# user：admin at 2018/11/5

from PyQt5.QtCore import QThread,pyqtSignal
import subprocess

class spiderFundThread(QThread):
    postSignal=pyqtSignal(str)

    def __init__(self,cmd):
        QThread.__init__(self)
        self.cmd=cmd

    def __del__(self):
        self.wait()

    def run(self):
        p=subprocess.Popen(self.cmd,
                           shell=True,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT
                           )

        while p.poll() is None:
            line=p.stdout.readline()
            line=line.strip()
            if line:

                self.postSignal.emit(str(line,encoding='UTF-8'))

        if p.returncode==0:
            self.postSignal.emit('爬取【天天基金网】基金排行成功！')
        else:
            self.postSignal.emit('爬取【天天基金网】基金排行错误！')